﻿<%@ Page Title="Đăng ký bảo hành và gia hạn bảo hành" Language="C#" MasterPageFile="~/App_MasterPages/Aquarius.Master"
    AutoEventWireup="true" CodeBehind="RegisterWarranty.aspx.cs" Inherits="PanasonicWarranty.UI.RegisterWarranty"  %>

<%@ Register Src="../UserControl/ucPaging.ascx" TagName="ucPaging" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="CssContent" runat="server">
    <link href="../css/uploadify.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .table2 tr.notvalid td{background: #FC9C9C !important;}
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ScriptContent" runat="server">
    <script src="../js/jquery.uploadify.js" type="text/javascript"></script>
    <script src="../js/pana_authorization.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            RegisterDialog();
            DatePicker("txtSearchFromDate,txtSearchToDate,txtRegisterDate");
            $("[id$='fuImport']").fileUpload({
                'uploader': '../js/uploader.swf',
                'cancelImg': '../img/cancel.png',
                'buttonText': 'Browse Files',
                'script': '../Handler/UpLoad3.ashx',
                'fileDesc': 'Excel file',
                'fileExt': '*.xls;*.xlsx;',
                'multi': false,
                'auto': false,
                'onComplete': function (file, data, response, c) {
                    $("#spUploadResult").html(c);
                }
            });
            SetBackgroundRowNotValid();
            CheckEnable($("[id$=ddlWarrantyType]").val());
        });
        function SetBackgroundRowNotValid() {
            $("[name=hdfValidate],[id$=grvData]").each(function () {
                if ($(this).val() == "False") {
                    $(this).closest("tr").addClass("notvalid");
                }
            });
        }
        function Authorize(role) {
            return Check_Authorize("{'roles': " + JSON.stringify(role) + "}");
        }

        function CheckSelected() {
            if ($(":checkbox:checked", "[id$=grvData] td").length == 0) {
                jAlert("Chưa có dữ liệu được chọn");
                return false;
            }
            return confirm("Xác nhận hành động!");
        }
        function CheckEnable(val) {
            var obj = $('[id$=ddlWarrantyPackage]')
            if (val == 'ĐKBH') {
                obj.val('');
                obj.prop('disabled', true);
            }
            else {
                obj.prop('disabled', false);
            }
        }

        function SetNew() {
            $("[id$=lbError]").html("");
            ResetControl("pnl_dialog1");
            $("[id$=hdfAction]").val("AddNew");
            $(".ui-autocomplete-input").val('');
            $("[id$=txtRegisterDate]").val(FormatDate(new Date()));
            OpenDialog('dialog1', 355);
            return false;
        }

        function SetEdit(id) { 
            $("[id$=hdfAction]").val("Editing");
            $("[id$=hdfID]").val(id);
            $.ajax({
                type: "POST",
                url: 'RegisterWarranty.aspx/GetWarrantyWaiting',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                beforeSend: function () {
                    $("#progress").show();
                },
                complete: function () {
                    $("#progress").hide();
                },
                data: "{'id':" + JSON.stringify(id) + "}",
                success: function (data) {
                    if (data.d != null) {
                        $("[id$=txtPhone]").val(data.d.CustomerPhone);
                        $("[id$=txtModelCode]").val(data.d.ModelCode);
                        $("[id$=txtProductCode]").val(data.d.ProductCode);
                        $("[id$=txtRegisterDate]").val(ParseJsonDate(data.d.RegisterDate));
                        $("[id$=ddlWarrantyType]").val(data.d.WarrantyType);
                        $("[id$=ddlWarrantyPackage]").val(data.d.WarrantyPackageCode);
                        $("[id$=lbError]").html("");
                        OpenDialog('dialog1', 355);
                    }
                    else {
                        jAlert("Dữ liệu không tồn tại hoặc đã được xử lý");
                    }
                }
            });
        }
        function Delete(obj, id) {
            if (confirm("Xác nhận hành động xóa")) {
                if (!Authorize("Write")) {
                    jAlert("Bạn không có quyền thực hiện chức năng này");
                    return false;
                }
                $.ajax({
                    type: "POST",
                    url: 'RegisterWarranty.aspx/DeleteWarrantyWaiting',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    beforeSend: function () {
                        $("#progress").show();
                    },
                    complete: function () {
                        $("#progress").hide();
                    },
                    data: "{'id':" + JSON.stringify(id) + "}",
                    success: function (data) {
                        $(obj).closest("tr").remove();
                    }
                });
            }
            return false;
        }
    </script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <div class="row-fluid">
        <div class="span12">
            <div class="head">
                <div class="isw-grid">
                </div>
                <h1>Điều kiện tìm kiếm</h1>
                <div class="clear"></div>
            </div>
            <div class="block-fluid" style="padding: 10px 0px 5px 10px">
                <table width="100%" cellspacing="0" cellpadding="0" class="">
                    <tbody>
                        <tr>
                            <td style="width:150px">Model sản phẩm</td>
                            <td><asp:TextBox ID="txtSearchModelCode" runat="server" /></td>
                            <td>Số máy</td>
                            <td><asp:TextBox ID="txtSearchProductCode" runat="server" /></td>
                            <td>Điện thoại KH</td>
                            <td><asp:TextBox ID="txtSearchPhone" runat="server" onkeypress="return ValidateKeypress(/\d+/,event);" /></td>
                        </tr>
                        <tr>
                            <td>Ngày đăng ký bảo hành</td>
                            <td><asp:TextBox ID="txtSearchFromDate" runat="server" /></td>
                            <td>Đến</td>
                            <td><asp:TextBox ID="txtSearchToDate" runat="server" /></td>
                            <td>&nbsp;</td><td>&nbsp;</td>
                            
                        </tr>
                        <tr>
                            <td>Loại đăng ký</td>
                            <td>
                                <asp:DropDownList ID="ddlSearchWarrantyType" runat="server">
                                    <asp:ListItem Value="">-----</asp:ListItem>
                                    <asp:ListItem Value="ĐKBH">Đăng ký</asp:ListItem>
                                    <asp:ListItem Value="GHBH">Gia hạn</asp:ListItem>
                                </asp:DropDownList>
                            </td>
                            <td>Trạng thái xác nhận</td>
                            <td>
                                <asp:DropDownList ID="ddlSearchApproved" runat="server">
                                    <asp:ListItem Value="">-----</asp:ListItem>
                                    <asp:ListItem Value="True">Đã xác nhận</asp:ListItem>
                                    <asp:ListItem Value="False">Chưa xác nhận</asp:ListItem>
                                </asp:DropDownList>
                            </td>
                            <td>Trạng thái dữ liệu</td>
                            <td>
                                <asp:DropDownList ID="ddlSearchIsValid" runat="server">
                                    <asp:ListItem Value="">-----</asp:ListItem>
                                    <asp:ListItem Value="True">Hợp lệ</asp:ListItem>
                                    <asp:ListItem Value="False">Không hợp lệ</asp:ListItem>
                                </asp:DropDownList>
                            </td>
                        </tr>
                    </tbody>
                </table>
                <div style="text-align: center">
                    <asp:Button ID="btnSearch" runat="server" Text="Tìm kiếm" OnClick="btnSearch_Click"
                        CssClass="btn" />
                </div>
            </div>
        </div>
    </div>
    <div class="row-fluid">
        <div class="span12">
            <div class="head">
                <div class="isw-grid"></div>
                <h1>Danh sách sản phẩm đăng ký bảo hành chờ duyệt</h1>
                <ul class="buttons">
                    <li><asp:LinkButton CssClass="isw-donw_circle" ID="lbtnExportAll" runat="server" OnClick="lbtnExportAll_Click" ToolTip="Export toàn bộ dữ liệu đăng ký"/></li>
                    <li><asp:LinkButton CssClass="isw-minus" ID="lbtnDeleteAll" runat="server" OnClick="lbtnDeleteAll_Click" ToolTip="Xóa toàn bộ dữ liệu lỗi" 
                            OnClientClick="return confirm('Xác nhận hành động xóa?');"/></li>
                    <li><asp:LinkButton CssClass="isw-ok" ID="lbtnApprovedAll" runat="server" OnClick="lbtnApprovedAll_Click" ToolTip="Duyệt toàn bộ được chọn" 
                            OnClientClick="return CheckSelected();"/></li>
                    <li><asp:LinkButton CssClass="isw-download" ID="btnDownload" runat="server" 
                            ToolTip="Download mẫu file upload" onclick="btnDownload_Click" /></li>
                    <li><asp:LinkButton CssClass="isw-attachment" ID="btnUpload" runat="server" 
                            ToolTip="Import danh sách" OnClientClick="$('#spUploadResult').html(''); return OpenDialog('dialog2',400);" /></li>
                    <li><asp:LinkButton CssClass="isw-plus" ID="lbtnAddNew" runat="server" OnClientClick="return SetNew();" ToolTip="Thêm mới dữ liệu" /></li>
                </ul>
                <div class="clear">
                </div>
            </div>
            <div class="block-fluid table-sorting">
                <div class="dataTables_wrapper" id="tSortable_wrapper">
                    <div class="dataTables_length">
                        <label>
                            Hiển thị
                            <asp:DropDownList ID="tSortable_length" size="1" aria-controls="tSortable" runat="server"
                                OnSelectedIndexChanged="tSortable_length_SelectedIndexChanged" AutoPostBack="true">
                                <asp:ListItem Value="5" />
                                <asp:ListItem Value="10" />
                                <asp:ListItem Value="25" />
                                <asp:ListItem Value="50" Selected="True" />
                                <asp:ListItem Value="100" />
                                <asp:ListItem Value="200" />
                                <asp:ListItem Value="250" />
                                <asp:ListItem Value="300" />
                                <asp:ListItem Value="400" />
                                <asp:ListItem Value="500" />
                            </asp:DropDownList>
                            dòng</label>
                    </div>
                    <div>
                        <uc1:ucPaging ID="pagingtop" runat="server" />
                    </div>
                    <asp:GridView ID="grvData" CssClass="table2 dataTable" runat="server" 
                        AutoGenerateColumns="false" Width="100%" ShowHeaderWhenEmpty="true" onrowcommand="grvData_RowCommand">
                        <Columns>
                            <asp:TemplateField HeaderText="STT" ItemStyle-CssClass="STT">
                                <ItemTemplate>
                                    <%#(Container.DataItemIndex + 1) + (pagingtop.CurrentPage - 1) * pagingtop.PageSize%>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField HeaderText="Điện thoại KH" DataField="CustomerPhone" ItemStyle-CssClass="Phone"/>
                            <asp:BoundField HeaderText="Model" DataField="ModelCode" ItemStyle-CssClass="width1"/>
                            <asp:BoundField HeaderText="Số máy" DataField="ProductCode" ItemStyle-CssClass="width1"/>
                            <asp:BoundField HeaderText="Ngày mua hàng" DataField="RegisterDate" DataFormatString="{0:d}" ItemStyle-CssClass="DateTime"/>
                            <asp:BoundField HeaderText="Ngày ĐK" DataField="CreatedDate" DataFormatString="{0:d}" ItemStyle-CssClass="DateTime"/>
                            <asp:BoundField HeaderText="Loại ĐK" DataField="WarrantyType" ItemStyle-CssClass="DateTime" />
                            <asp:BoundField HeaderText="ĐK qua" DataField="RegisteredFrom" ItemStyle-CssClass="DateTime"/>
                            <asp:BoundField HeaderText="Gói GH" DataField="WarrantyPackageCode" ItemStyle-CssClass="DateTime"/>
                            <asp:BoundField HeaderText="Ghi chú" DataField="Description" ItemStyle-CssClass="Description"/>
                            <asp:TemplateField HeaderText="Chức năng" ItemStyle-CssClass="Function">
                                <ItemTemplate>
                                    <input type="hidden" name="hdfValidate" value='<%# (bool)Eval("IsValid")%>' />
                                    <asp:LinkButton ID="lbtnApproved" runat="server" Text="Duyệt"
                                        CommandName="Approving" CommandArgument='<%#Eval("WarrantyWattingID")%>' 
                                        Visible='<%# (bool)Eval("IsValid") == false ? false : (!(bool?)Eval("Approved") ?? true) %>'/>
                                    &nbsp;
                                    <a href="#" onclick='javascript:SetEdit(<%#Eval("WarrantyWattingID")%>); return false;' style='visibility:<%# (Eval("Approved") == null? "visible": ((bool)Eval("Approved"))? "hidden" : "visible")%>'>Sửa</a>
                                    &nbsp;
                                    <a href="#" onclick='return Delete(this, <%#Eval("WarrantyWattingID")%>);' style='visibility:<%# (Eval("Approved") == null? "visible": ((bool)Eval("Approved"))? "hidden" : "visible")%>'>Xóa</a>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText='<input type="checkbox" id="chkCheckAll" onclick="CheckAllCheckBox(this);" title="Chọn toàn bộ"'>
                                <ItemStyle HorizontalAlign="Center" Width="40px" />
                                <ItemTemplate>
                                    <asp:HiddenField ID="hdfItemID" runat="server" Value='<%#Eval("WarrantyWattingID")%>' />
                                    <asp:CheckBox ID="chkCheckItem" runat="server" Visible='<%# (bool)Eval("IsValid") == false ? false : (!(bool?)Eval("Approved") ?? true) %>'/>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                    <div class="dataTables_info" id="tSortable_info">
                        <asp:Literal ID="ltrInfo" runat="server" />
                    </div>
                    <div class="dataTables_paginate paging_full_numbers" id="tSortable_paginate">
                        <uc1:ucPaging ID="pagingbottom" runat="server" />
                    </div>
                </div>
                <div class="clear">
                </div>
            </div>
        </div>
    </div>
    <div class="ui-widget-overlay ui-front" id="progress" style="display:none">
        <img src='<%=ResolveUrl("~/images/loading.gif")%>' alt="Loading..." style="position: fixed; top: 50%; left: 50%" />
    </div>
    <div class="dialog" id="dialog1" title="Thông tin đăng ký bảo hành" style="display: none;">
        <asp:Panel ID="pnl_dialog1" runat="server" CssClass="block">
            <asp:HiddenField ID="hdfID" Value="" runat="server" />
            <asp:HiddenField ID="hdfAction" Value="" runat="server" />
            <table width="100%" cellpadding="2" cellspacing="2" >
                <tr>
                    <td>Điện thoại KH</td>
                    <td><asp:TextBox ID="txtPhone" runat="server" onkeypress="return ValidateKeypress(/\d+/,event)" /></td>
                </tr>
                <tr>
                    <td>Model</td>
                    <td><asp:TextBox ID="txtModelCode" runat="server" /></td>
                </tr>
                <tr>
                    <td>Số máy</td>
                    <td><asp:TextBox ID="txtProductCode" runat="server"/></td>
                </tr>
         
                <tr>
                    <td>Ngày đăng ký</td>
                    <td>
                        <asp:TextBox ID="txtRegisterDate" runat="server" />
                    </td>
                </tr>
                <asp:Panel ID="pnlDKBH" runat="server">
                <tr>
                    <td>Loại đăng ký</td>
                    <td>
                        <asp:DropDownList ID="ddlWarrantyType" runat="server" onchange="CheckEnable(this.value);">
                            <asp:ListItem Value="ĐKBH">Đăng ký</asp:ListItem>
                            <asp:ListItem Value="GHBH">Gia hạn</asp:ListItem>
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr>
                    <td>Gói gia hạn</td>
                    <td><asp:DropDownList ID="ddlWarrantyPackage" runat="server" /></td>
                </tr>
                </asp:Panel>
            </table>
            <div style="text-align:center; width:100%; color:Red"><asp:Label ID="lbError" runat="server" EnableViewState="false"/></div>
            <div class="dr"><span></span></div>
            <div style="text-align: right">
                <asp:Button ID="btnSave" CssClass="btn" runat="server" Text="Lưu" 
                    onclick="btnSave_Click" />
                <input type="button" class="btn" value="Đóng" onclick="$('#dialog1').dialog('close'); return false;" />
            </div>
        </asp:Panel>
    </div>
    <div class="dialog" id="dialog2" title="Lựa chọn file Import" style="display: none;">
        <asp:Panel ID="pnl_dialog2" runat="server" CssClass="block">
            <div>
                <asp:FileUpload ID="fuImport" runat="server" />
            </div>
            <div style="text-align:center; color:Red">
                <span id="spUploadResult"></span>
            </div>
            <div class="dr"><span></span></div>
            <div style="text-align: right">
                <input type="button" class="btn" value="Import" onclick='$("[id$=fuImport]").fileUploadStart(); return false;' />
                <asp:Button ID="btnCancel" CssClass="btn" Text="Đóng" OnClick="btnCancel_Click" OnClientClick="$('[id$=fuImport]').fileUploadClearQueue(); $('#dialog2').dialog('close');" runat="server" />
            </div>
        </asp:Panel>
    </div>
</asp:Content>
